package com.servlet.model.base;

import java.io.Serializable;

/**
 * Zone géographique dans la base de donnée
 * @author Jing Jing
 */
public class Area implements Serializable {

	public static Area areaVide = new Area(0, "Inconnu" , "Inconnu");
	private int city_code;
	private String country;
	private String city;
	
	
	public Area()
	{
		city_code = 0;
		country = null;
		city = null;
	}
	
	public Area(int city_code, String country, String city)
	{
		this.city_code = city_code;
		this.country = country;
		this.city = city;
	}
	
	public Area(Area area)
	{
		this.city_code = area.city_code;
		this.country = area.country;
		this.city = area.city;
	}

	/**
	 * GETTERS AND SETTERS
	 */
	
	public int getCity_code()
	{
		return city_code;
	}
	
	public int getHCode()
	{
		return (city_code + country + city).hashCode();
	}
	
	public String getCity()
	{
		return city;
	}
	
	public String getCountry()
	{
		return country;
	}
	
	public void setCity_code(int city_code)
	{
		this.city_code = city_code;
	}
	
	public void setCity(String city)
	{
		this.city = city;
	}
	
	public void setCountry(String country)
	{
		this.country = country;
	}
	
	
	/**
	 * @return une string comprenant l'instruction SQL pour ajouter la zone à la base de donnée 
	 */
	public String generateInsertSQL()
	{
		String insertSQL = "INSERT INTO area VALUES (" + getHCode() + " ,'" + city_code + "' ,'" + country
				+ "' ,'" + city + "')";		
		System.out.println(insertSQL);
		
		return insertSQL;
	}
}
